
#ifndef  RING_BUF_H
#define  RING_BUF_H

#include "stdint.h"
#include "stdbool.h"
#include "stdio.h"

typedef struct
{
	void*		 uart;
	volatile uint32_t write_index;
	volatile uint32_t read_index;
	volatile uint32_t peek_index;

    volatile uint32_t last_read_index; //数据锁前的读索引
    volatile uint32_t last_write_index; //数据锁前的写索引
    volatile uint32_t lock_read_index; //数据锁开启后的读索引
	volatile uint32_t lock_length; //锁数据长度
	uint32_t max_size_mask;    
    volatile bool lock_flag; //是否开启数据锁功能
	uint8_t* buff_addr;
}RING_BUF_DEF_STRUCT;

void RingBuf_Init(RING_BUF_DEF_STRUCT* ring_buf, uint8_t* src_buf, uint32_t src_buf_maxsize);
uint32_t RingBuf_Read(RING_BUF_DEF_STRUCT* src_ringbuf, uint32_t len, uint8_t* dst_buf);
void RingBuf_Peek (RING_BUF_DEF_STRUCT* src_ringbuf, uint32_t len , uint8_t* dst_buf);
void RingBuf_Peek_Pos_Change(RING_BUF_DEF_STRUCT* src_ringbuf, uint32_t offset);
uint32_t RingBuf_Peeked_Counter(RING_BUF_DEF_STRUCT* src_ringbuf);
void RingBuf_Peeked_Flush(RING_BUF_DEF_STRUCT* src_ringbuf);
void RingBuf_Peeked_Reset (RING_BUF_DEF_STRUCT* src_ringbuf);
bool RingBuf_Write(RING_BUF_DEF_STRUCT* des_ringbuf,uint8_t* src, uint32_t len);
void RingBuf_Flush(RING_BUF_DEF_STRUCT* src_ringbuf);
uint32_t RingBuf_Count(RING_BUF_DEF_STRUCT* src_ringbuf);
uint32_t RingBuf_UnusedCount(RING_BUF_DEF_STRUCT* src_ringbuf);
uint32_t RingBuf_PeekCount(RING_BUF_DEF_STRUCT* src_ringbuf);
void RingBuf_ReadIndex_Change(RING_BUF_DEF_STRUCT* src_ringbuf, uint32_t offset);

//临时增加的接口
void RingBuf_Up_Lock(RING_BUF_DEF_STRUCT* src_ringbuf);
void RingBuf_Free_Lock(RING_BUF_DEF_STRUCT* src_ringbuf);

#endif 
